/**
 * File MsgToSendModel.java 
 */
package cs.model;

import java.util.ArrayList;
import java.util.Observable;

import cs.entity.UserTextMessage;

/**
 * Represents a queue of UserTextMessages.<p>
 * Package  cs.model
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 */
public class MsgToSendModel extends Observable {
	/**
	 * text messages sending queue
	 */
	private ArrayList<UserTextMessage> msgToSend;
	
	/**
	 * constructor
	 */
	public MsgToSendModel(){
		msgToSend = new ArrayList<UserTextMessage>();
	}
	
	/**
	 * Add to queue a new UserTextMessage
	 * @param msg
	 */
	public void addMsgToSend(UserTextMessage msg){
		System.out.println("New  message to send added to model"); 
		msgToSend.add(msg);
		setChanged();
		notifyObservers(msg);
	}
	
	/**
	 * get and remove the first message to send 
	 * @return UserTextMessage or null if the queue is empty
	 */
	public UserTextMessage getRemoveMsgToSend() {
		//check if the queue is empty
		if (!(msgToSend.isEmpty())) {
			UserTextMessage msgSend = msgToSend.get(0); 
			msgToSend.remove(0); 
			return msgSend ; 
		} else {
			System.err.println(""); 
			return null ; 
		}
	}
	
	/**
	 * Remove all received messages
	 * used when the local user are disconnecting
	 */
	public void removeAllMsgToSend() {
		msgToSend.clear(); 
	}
}
